{extend name="wap/default_new/base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/foundation.css">
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/normalize.css">
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/common-v4.4.css">
<meta class="foundation-data-attribute-namespace">
<meta class="foundation-mq-xxlarge">
<meta class="foundation-mq-xlarge">
<meta class="foundation-mq-large">
<meta class="foundation-mq-medium">
<meta class="foundation-mq-small">
<style  type="text/css">
.button-submit{width:90%;margin:50px auto 0;}
.button-submit button{color:#FFF;background-color:#E03115;font-size:15px;border:none;line-height:40px;height:40px;}
.mt-55.mlr-15 input{box-shadow: none;margin: 0;height: 35px;border: none;max-width: 72%;min-width: 60%;display: inline-block;font-size: 14px;}
.mt-55.mlr-15>div{line-height:50px;padding-left:15px;overflow: hidden;background: #fff;}
.mt-55.mlr-15>div:first-child{margin-top:45px;}
.mt-55.mlr-15>div>span{width: 28%;font-size: 14px;display: block;float:left;}
.mt-55.mlr-15>div>span.left-img{width: 16%;}
.mt-55.mlr-15>div>span>img{width: 26px;height:auto;float: left;margin-top: 16px;}
.border_right{border-right: 1px solid #ddd;height: 24px;width: 2px;float: left;margin-top: 16px;margin-left: 14px;}
.mt-55.mlr-15 input:focus{background: #fff;}
.personal-center .value{font-size: 12px;color: #999;}
.personal-center .value.touxiang{display: block;width: 40px;height: 40px;line-height: 40px;text-align: center;border-radius: 50%;border: 1px solid #e6e6e6;overflow: hidden;}
.personal-center .value img{max-width:100%;max-height: 100%;width:auto;height:auto;vertical-align: middle;    display: block;}
.personal-center .arrow, .personal-center .head-arrow{margin-top: 10px;}
.personal-center .set_a{color: #29afe4;}
.mt-55.mlr-15>div.threeBind{padding-left: 0;border-bottom: 1px solid #ddd;border-top: 1px solid #ddd;margin-top: 54px;}

.sendOutCode{border: 1px solid #E03115!important;color: #E03115;padding:0;width: 30px;background: #fff;border-radius: 4px;min-width: 25% !important;height: 25px;font-size: 12px;margin-left: 20px;}
</style>
{/block}

{block name="goodsHead"}
<section class="head">
	<a class="head_back" id="backoutapp" href="{:__URL('APP_MAIN/login')}"><i class="icon-back"></i></a>
	<div class="head-title" id="title">忘记密码</div>
</section>
{/block}
{block name="main"}
<!-- 密码修改 -->
{if condition="$type == 1"}
<!-- 手机 -->
<form class="mt-55 mlr-15" id="editpassword" style="background-color:#fff;margin:45px 0 0 0;">
	<div>
		<span>手机号：</span>
		<input type="text" name="mobile" id="mobile" style="margin:0;height:50px;border-bottom:none;" placeholder="输入11位手机号" >
	</div>
	<div>
		<span>验证码</span>
		<input type="text" id="mobile-code" name="mobile-code" placeholder="请输入手机验证码" style="max-width: 32%;min-width: 30%;"/>
		<input type="button" class="sendOutCode sendcode" id="send_mobile" value="获取验证码" style="height: 30px;margin-left: 20px;">
	</div>
	<div><span>{:lang('member_new_password')}：</span>
		<input type="text" id="mobile-pass" name="mobile-pass" style="box-shadow:none;margin:0;height:35px;border:none;width:auto;display:inline-block;" placeholder="{:lang('member_new_password')}" onfocus="$(this).attr('type','password')"/>
		<span>{:lang('confirm_new_password')}：</span>
		<input type="text" id="mobile-new-pass" name="mobile-new-pass" placeholder="{:lang('confirm_new_password')}" onfocus="$(this).attr('type','password')">
	</div>
</form>
{else/}
<!-- 邮箱 -->
<form class="mt-55 mlr-15" id="editpassword" style="background-color:#fff;margin:45px 0 0 0;">
	<div>
		<span>邮箱号：</span>
		<input type="text" name="email" id="email" style="margin:0;height:50px;border-bottom:none;" placeholder="输入注册邮箱号" >
	</div>
	<div>
		<span>验证码</span>
		<input type="text" id="email-code" name="email_code" placeholder="请输入邮箱验证码" style="max-width: 32%;min-width: 30%;"/>
		<input type="button" class="sendOutCode sendcode" id="send_mobile" value="获取验证码" style="height: 30px;margin-left: 20px;">
	</div>
	<div><span>{:lang('member_new_password')}：</span>
		<input type="text" id="email-pass" name="email-pass" style="box-shadow:none;margin:0;height:35px;border:none;width:auto;display:inline-block;" placeholder="{:lang('member_new_password')}" onfocus="$(this).attr('type','password')"/>
		<span>{:lang('confirm_new_password')}：</span>
		<input type="text" id="email-new-pass" name="email-new-pass"
		 placeholder="{:lang('confirm_new_password')}" onfocus="$(this).attr('type','password')">
	</div>
</form>
{/if}

<div id="saveBtn" class="button-submit">
	<a href="javascript:void(0)">
		<button  id="btn_submit">{:lang('member_preservation')}</button>
	</a>
</div>
{/block}
{block name="bottom"}{/block}
{block name="javascript"}
<script type="text/javascript">
var sendtype = {$type};
$(document).ready(function(){
	//检测手机手机是否已注册
	$("#mobile").change(function(){
		var mobile = $("#mobile").val();
		$.ajax({
			type: "GET",
			url: "{:__URL('APP_MAIN/login/findpasswd')}",
			data: {"info":mobile,"type":"mobile"},
			success: function(data){
				//alert(JSON.stringify(data));
				if(data){
				}else{
					layer.msg('该手机号未注册');
					$("#mobile").focus();
					return false;
				}
			}
		});
	});
	
	//检测邮箱是否存在
	$("#email").change(function(){
		var email = $("#email").val();
		$.ajax({
			type: "GET",
			url: "{:__URL('APP_MAIN/login/findpasswd')}",
			data: {"info":email,"type":"email"},
			success: function(data){
				if(data){
				}else{
					layer.msg('该邮箱未注册');
					$("#email").focus();
					return false;
				}
			}
		});
	});

	//发送手机邮箱验证码
	$(".sendcode").click(function(){
		if(sendtype == 1){
			var mobile = $("#mobile").val();
			/*var vertification = $("#captcha-mobile").val();*/
			var type ="sms";
			//验证手机号格式是否正确
			if(mobile.search(/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/) == -1){
				layer.msg('请输入正确的手机格式');
				$("#mobile").focus();
				return false;
			}
		}else{
			var mobile = $("#email").val();
			/*var vertification = $("#captcha-email").val();*/
			var type ="email";
			//验证邮箱格式是否正确
			if(mobile.search(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/) == -1){
				layer.msg('请输入正确的邮箱格式');
				$("#email").focus();
				return false;
			}
		}
		//验证手机号邮箱是否已经注册
		$.ajax({
			type: "post",
			url: "{:__URL('APP_MAIN/login/forgotvalidation')}",
			data: {"type":type,"send_param":mobile},
			async: false,
			success: function(data){
				if (data['code'] == 0) {
					if(sendtype == 1){
						layer.msg(data.message);
						$("#mobile").attr("disabled",true);
					}else{
						layer.msg(data.message);
						$("#email").attr("disabled",true);
					}
					time();
				}else{
					layer.msg(data.message);
					return false;
				}
			}
		});
	});
});

var wait=120; 
function time() { 
	if (wait == 0) {
		$(".sendcode").removeAttr("disabled");
		$(".sendcode").val("获取验证码"); 
		wait = 120;
	} else { 
		$(".sendcode").attr("disabled", 'disabled');
		$(".sendcode").val(wait+"s后重新发送"); 
		wait--;
		setTimeout(function() {time()},1000);
	}
}

$("#btn_submit").click(function(){
	if(sendtype == 1){
		var type = "mobile";
		var mobile = $("#mobile").val();
			var mobile_code = $("#mobile-code").val();
			var mobile_pass = $("#mobile-pass").val();
			var mobile_new_pass = $("#mobile-new-pass").val();
			if(mobile.length==0){
				layer.msg("请输入您注册的手机号码");
				$("#mobile").focus();
				return false;
			}
			var result = '';
			if(mobile_code.length==0){
				layer.msg("请输入手机验证码");
				$("#mobile-code").focus();
				return false;
			}else{
				$.ajax({
					type : "post",
					url : "{:__URL('APP_MAIN/login/check_find_password_code')}",
					async : false,
					data : {"send_param" : mobile_code},
					success : function(data){
						if(data['code']==0){
						}else{
							layer.msg(data.message);
							$("#mobile-code").focus();
							result = true;
						}
						return result;
					}
				})
			}
			if(result){
				return false;
			}
			if(mobile_pass.length<6){
				layer.msg('登录密码不能少于 6 个字符');
				$("#mobile-pass").focus();
				return false;
			}
			if(mobile_new_pass != mobile_pass){
				layer.msg('两次输入的密码不一致');
				$("#mobile-new-pass").focus();
				return false;
			}
			$.ajax({
				type : "post",
				url : "{:__URL('APP_MAIN/login/setnewpasswordbyemailormobile')}",
				data : {"userInfo":mobile,"password":mobile_pass,"type":"mobile"},
				success : function(data){
					if(data['code'] == 1){
						location.href=__URL("APP_MAIN/login");
					}else{
						layer.msg(data['message']);
						setTimeout(function(){
							location.reload()
						},2000);
					}
				}
			})
		}else{
			var type = "email";
			var email = $("#email").val();
			var email_code = $("#email-code").val();
			var email_pass = $("#email-pass").val();
			var email_new_pass = $("#email-new-pass").val();
			if(email.length==0){
				layer.msg('请输入您注册的邮箱');
				$("#email").focus();
				return false;
			}
			var result = '';
			if(email_code.length==0){
				layer.msg('请输入邮箱验证码');
				$("#email-code").focus();
				return false;
			}else{
				$.ajax({
					type : "post",
					url : "{:__URL('APP_MAIN/login/check_find_password_code')}",
					async : false,
					data : {"send_param" : email_code},
					success : function(data){
						if(data['code']==0){
						}else{
							layer.msg(data['message']);
							$("#email-code").focus();
							result = true;
						}
						return result;
					}
				})
			}
			if(result){
				return false;
			}
			if(email_pass.length<6){
				layer.msg('登录密码不能少于 6 个字符');
				$("#email-pass").focus();
				return false;
			}
			if(email_new_pass != email_pass){
				layer.msg('两次输入的密码不一致');
				$("#email-new-pass").focus();
				return false;
			}
			$.ajax({
				type : "post",
				url : "{:__URL('APP_MAIN/login/setnewpasswordbyemailormobile')}",
				data : {"userInfo":email,"password":email_pass,"type":"email"},
				success : function(data){
					if(data['code'] == 1){
						location.href=__URL("APP_MAIN/login");
					}else{
						layer.msg(data['message']);
							setTimeout(function(){
							location.reload()
						},2000);
					}
				}
			})
		}
});
</script>
{/block}